package com.cy.member;

import java.awt.Point;
import java.util.ArrayList;

import com.cy.member.parent.ChineseChessman;

/**
 * 车
 * @author CY
 */
public class Che extends ChineseChessman {
	
	/**
	 * @param who true红方，false黑方
	 */
	public Che(boolean who) {
		if(who) {//红车
			this.setBackground("image/红车.GIF");
		} else {//黑车
			this.setBackground("image/黑车.gif");
		}
		//生成棋子
		this.generateChessman(who);
	}

	/**
	 * 车的移动策略
	 * 首先保证垂直移动
	 * 其次在起始位置到目标位置不可以有其他棋子
	 */
	@Override
	public boolean move(Point site, ArrayList<Point> points) {
		//起点坐标
		Point origin = getChessman().getSite();
		//垂直移动
		if(origin.x == site.x && points != null) {
			for(Point point : points) {
				if((point.y < origin.y && point.y > site.y) || (point.y > origin.y && point.y < site.y)){
					return false;
				}
			}
		} else if(origin.y == site.y && points != null){//水平移动
			for(Point point : points) {
				if((point.x < origin.x && point.x > site.x) || (point.x > origin.x && point.x < site.x)){
					return false;
				}
			}
		} else {
			return false;
		}
		getChessman().setSite(site);
		return true;
	}
}
